import axios from "axios";
import { Message } from 'element-ui'
axios.defaults.withCredentials = true;
axios.defaults.baseURL = 'http://10.208.2.47:8080';
// 请求头添加token
// axios.defaults.headers.common['token'] = sessionStorage.getItem('token');
// 请求发送拦截
axios.interceptors.request.use((request) => {
        // request.data.token=sessionStorage.getItem('token');
        var token = sessionStorage.getItem('token');
        if (token != null) {
            token = token.substring(1, token.length - 1);
            request.headers.token = token;
            // console.log(token);
        }
        return request;
    })
    // 配置一个响应拦截器，拦截所有的后台响应
axios.interceptors.response.use(function(response) {
        var code = response && response.data.code;
        if (code == -3 || code == -2) {
            alert("未登录，请登录...");
            vm.$router.push('/login'); // 跳转  
            Message({ message: response.data.message, type: "error" })
        }
        return response;
    }, function(err) {
        // 处理响应的错误信息
        console.log(err)
    })
    //登录
export const requestLogin = (params) => {
    return axios.post(`/system/login`, params).then((res) => res.data);
};
//用户管理
export const getUserList = (params) => {
    return axios.get(`/user/list`, { params: params });
};

export const getUserListPage = (params) => {
    return axios.get(`/user/listpage`, { params: params });
};

export const removeUser = (params) => {
    return axios.get(`/user/remove`, { params: params });
};

export const batchRemoveUser = (params) => {
    return axios.get(`/user/batchremove`, { params: params });
};

export const editUser = (params) => {
    return axios.get(`/user/edit`, { params: params });
};

export const addUser = (params) => {
    return axios.get(`/user/add`, { params: params });
};